<%@ page language="java" pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp"%>
<%@include file="/common/css.jsp"%>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
		<!-- 
		<link rel="stylesheet" type="text/css" href="${base}/css/caas_style.css" />
		 -->		
		<script type="text/javascript" src="${base }/js/DatePicker/WdatePicker.js"></script>
		<script type="text/javascript" src="${base }/js/jquery/jquery-1.3.min.js"></script>
		<script type="text/javascript" src="${base }/js/jquery/lhgdialog/lhgcore.min.js"></script>
		<script type="text/javascript" src="${base }/js/jquery/lhgdialog/lhgdialog.min.js"></script>
		<script type="text/javascript" src="${base }/js/page.js"></script>
		
		<script language="javascript">
		 jQuery(document).ready(function(){			   
			   //添加按钮单击事件
			   jQuery(".addBtn").click(function(){
					var param = {};
					param.operate = "add";
				    var dg = new J.dialog({ title: '添加目录信息对话框', 
				    	iconTitle:false,maxBtn:false,resize:false,
				    	cover:true,width:600,height:300,
				    	page: '${base}/forward?url=pages.directory.directoryView',
				    	args:param});
					dg.ShowDialog();
			   });
			   
			   //修改按钮单击事件
			   jQuery(".updateBtn").click(function(){
			   		if(isDispose(jQuery(this))){
			   			alert("该目录已办理完成，不能修改该目录!");
			   			return;
			  		}
			   		var param = {};
			   		param.operate = "update";
			   		param.dirId = jQuery(this).val();
				    var dg = new J.dialog({ title: '修改目录信息对话框', 
				    	iconTitle:false,maxBtn:false,resize:false,
				    	cover:true,width:600,height:300,
				    	page: '${base}/forward?url=pages.directory.directoryView',
				    	args:param});				    	
					dg.ShowDialog();
			   });
			   
			   	//查看按钮单击事件
			   jQuery(".showBtn").click(function(){
			   		var param = {};
			   		param.operate = "show";
			   		param.dirId = jQuery(this).val();
				    var dg = new J.dialog({ title: '查看目录信息对话框', 
				    	iconTitle:false,maxBtn:false,resize:false,
				    	cover:true,width:600,height:300,
				    	cancelBtnTxt:'关闭',
				    	page: '${base}/forward?url=pages.directory.directoryView',
				    	args:param});				    	
					dg.ShowDialog();
			   });
			   
			   //删除按钮单击事件
			   jQuery(".deleteBtn").click(function(){
			   		if(isDispose(jQuery(this))){
			   			alert("该目录已办理完成，不能删除该目录！");
			   			return;
			  		}
			   		if(confirm("你确认要删除该目录信息吗？")){
			   			var param = {};
			   			param.dirId = jQuery(this).val();
			   			jQuery.post("${base}/directory/delete",param,function(data,textStatus,jqXHR){
							if(data.success){
								alert("删除成功!");
								refush();
							}else{
								alert("删除失败!");
							}
						},'json');		
			   		}			   		
			   });
			   
			   //发布/取消发布单击事件
			   jQuery(".publishBtn").click(function(){
			   		var param = {};
			   		param.dirId = jQuery(this).val();
			   		param.status = jQuery(this).attr("status");
			   		var info = (param.status=="1"?"发布":"取消发布");
			   		var url = "${base}/directory/publish";			   		
			   		jQuery(this).attr("id","publish");
			   		if(isDispose(jQuery(this))){
			   			alert("该目录已办理完成，不能" + info);
			   			return;
			  		}
		   			jQuery.post("${base}/directory/publish",param,function(data,textStatus,jqXHR){
						if(data.success){
							alert(info + "成功!");
							jQuery("#publish").text(data.status == "1"?"发布":"取消发布");												
							jQuery("#publish").attr("status",data.status);	
							var txt = data.status == "1" ? "待发布" : "<font color='blue'>已发布</font>";	
							jQuery("#publish").parent().prev().prev().html(txt);
							jQuery("#publish").parent().parent().children("td:first-child").children("input:first-child").attr("_status",data.status);
							jQuery("#publish").removeAttr("id");	
						}else{
							alert(info + "失败!");
						}
					},'json');	
			   });
			   
			   	//办理完成单击事件
			   jQuery("#btn_dispose").click(function(){
			   		var url = "${base}/directory/dispose";
			   		var param = {};
			   		var $radio = jQuery("input[name='dirChk']:checked");	
			   		$radio.attr("id","dirChkId");		   		
			   		param.dirId = $radio.val();
			   		param.dispose = $radio.attr("dispose");
			   		var status = $radio.attr("_status");
			   		if(status==null){
			   			alert("请先选中相应的目录信息!");
			   			return;
			   		}else if(status != '2'){
			   			alert("只有已发布的目录才能执行办理完成操作!");
			   			return;
			   		}
			   		if(param.dispose == '2'){
			   			alert("该目录已办理完成!");
			   			return;
			   		}
			   		var info = param.dispose == "1"?"办理完成":"重新打开";
		   			jQuery.post("${base}/directory/dispose",param,function(data,textStatus,jqXHR){
						if(data.success){
							alert(info + "操作成功!");
							jQuery("#dirChkId").attr("dispose",data.dispose);
							jQuery("#dirChkId").parent().parent().children("td[name='td_status']").html("<font color='red'>已完成</font>");
							$radio.removeAttr("id");
						}else{
							alert(info + "操作失败!");
						}
					},'json');	
			   });
			   
			   //重新打开单击事件
			   jQuery("#btn_reopen").click(function(){
			   		var url = "${base}/directory/dispose";
			   		var param = {};
			   		var $radio = jQuery("input[name='dirChk']:checked");	
			   		$radio.attr("id","dirChkId");		   		
			   		param.dirId = $radio.val();
			   		param.dispose = $radio.attr("dispose");
			   		if(param.dispose==null){
			   			alert("请先选中相应的目录信息!");
			   			return;
			   		}else if(param.dispose == '1'){
			   			alert("该目录尚未办理完成，不能重新打开!");
			   			return;
			   		}
			   		var info = "重新打开";
		   			jQuery.post("${base}/directory/dispose",param,function(data,textStatus,jqXHR){
						if(data.success){
							alert(info + "操作成功!");
							jQuery("#dirChkId").attr("dispose",data.dispose);
							jQuery("#dirChkId").parent().parent().children("td[name='td_status']").html("<font color='blue'>已发布</font>");
							$radio.removeAttr("id");
						}else{
							alert(info + "操作失败!");
						}
					},'json');	
			   });
			   
			   //授权管理单击事件
			   jQuery("#btn_right").click(function(){
			   		var dirId = jQuery("input[name='dirChk']:checked").val();	
			   		if(dirId == null){
			   			alert("请先选中相应的目录信息!");
			   			return;
			   		}
			   		var param = {};
			   		param.dirId = dirId;
		   		 	var dg = new J.dialog({ title: '目录授权管理对话框', 
						    	iconTitle:false,maxBtn:false,resize:false,
						    	cover:true,width:500,height:310,
						    	page: '${base}/directory/listRight?dirId=' + dirId,
						    	args:param});
					dg.ShowDialog();
			   });
			   
			   //表格的行单击事件
			   jQuery("#DataGrid1 tr").click(function(){
			   		jQuery(this).children("td:first-child").children("input:first-child").attr("checked","true");
			   });
			   
			    function isDispose($a){
				 	var dispose = $a.parent().parent().children("td:first-child").children("input:first-child").attr("dispose");
				 	if(dispose == '2'){
				 		return true;
				 	}
				 	return false;
			   }	
	   
		  });
		  		  			   
	 	 function refush(){
	   	   window.location.href="${base}/directory/list";
		 }
		 
		
	</script>
	<title>目录管理</title>
	</head>
	<body>
		<table width="99%" border="0" cellspacing="0" cellpadding="0" align="center">
			<tr>
				<td valign="middle">
					<div class="search_bg">
						<form name="form1" method="post" action="${base }/directory/list">
						<table width="100%" border="0" align="left" cellpadding="0"
							cellspacing="0">
							<tr>
								<td align="right" width="10%" height="26">
									目录名称：
								</td>
								<td align="left" width="15%">
									<input type="text" name="dirname" value="${dirName }">
								</td>
								<td align="right" width="10%" height="26">
									目录编码：
								</td>
								<td align="left" width="15%">
									<input type="text" name="dircode" value="${dirCode }">
								</td>
								<td align="right" width="15%">
									创建时间：
								</td>
								<td align="left" width="25%">
									<input type="text"
										onFocus="WdatePicker({maxDate:'#F{$dp.$D(\'d4322\',{d:-3});}'})"
										id="d4321" name="starttime" class="Wdate" style="width: 100px" value="${startTime }">
									&nbsp;到									
									<input type="text"
										onFocus="WdatePicker({minDate:'#F{$dp.$D(\'d4321\',{d:3});}'})"
										id="d4322" name="endtime" class="Wdate" style="width: 100px" value="${endTime }">
								</td>
								<td width="10%" rowspan="2">
									<input type="submit" class="anniu" value="查询">
								</td>
							</tr>
						</table>
					</div>
				</td>
			</tr>
			<tr>
				<td>
					<div class="biaoge">
						<table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td colspan="6" class="biaoge_bg01" >
									目录列表
								</td>
							</tr>
							<tr>
								<td align="right" colspan="6" class="biaoge_bg02">
									<input type="button" value="添加" class="anniu addBtn"/>
									<input type="button" value="办理完成" id="btn_dispose" class="anniu">
									<input type="button" value="重新打开" id="btn_reopen" class="anniu">
									<input type="button" value="权限管理" id="btn_right" class="anniu">
								</td>
							</tr>
							<tr>
								<td>
									<table width="100%" border="0" cellspacing="1" cellpadding="0"
										class="FindAreaTable1" ID="DataGrid1">
										<tr>
											<th width="2%">
												&nbsp;
											</th>
											<th width="20%">
												目录名称
											</th>
											<th width="10%">
												目录编码
											</th>
											<th width="18%">
												硬盘路径
											</th>
											<th width="15%">
												备注
											</th>
											<th width="5%">
												状态
											</th>
											<th width="10%">
												创建时间
											</th>
											<th width="20%">
												操作
											</th>
										</tr>
										<c:choose>
											<c:when test="${pm.result eq null}">
												<tr>
													<td colspan="8">没有目录信息</td>
												</tr>
											</c:when>
											<c:otherwise>
												<c:forEach var="dir" items="${pm.result}" varStatus="status">
													<tr>
														<td>
															<c:choose>
																<c:when test="${dir.id eq 0}">
																	<input type="radio"  disabled/>
																</c:when>
																<c:otherwise>
																	<input type="radio" name="dirChk" _status="${dir.status }" dispose="${dir.dispose}" value="${dir.id}"/>
																</c:otherwise>
															</c:choose>
														</td>
														<td>${dir.dirName}</td>
														<td>${dir.dirCode}</td>	
														<td>${dir.path}</td>	
														<td>${dir.remark}</td>
														<td name="td_status">
															<c:choose>
																<c:when test="${dir.status=='1' }">
																	待发布
																</c:when>
																<c:when test="${dir.status=='2' && dir.dispose == '1'}">
																	<font color="blue">已发布</font>
																</c:when>
																<c:when test="${dir.status=='2' && dir.dispose == '2'}">
																	<font color="red">已完成</font>
																</c:when>
															</c:choose>
														</td>	
														<td>${dir.createTime}</td>											
														<td>
															<c:choose>
																<c:when test="${dir.id eq 0}">
																	&nbsp;
																</c:when>
																<c:otherwise>
																	<a href="#" name="a_modify" class="updateBtn" value="${dir.id}">修改</a>&nbsp;
																	<a href="#" name="a_show" class="showBtn" value="${dir.id}">查看</a>&nbsp;
																	<a href="#" name="a_del" class="deleteBtn" value="${dir.id}">删除</a>&nbsp;
																	<a href="#" name="a_publish" class="publishBtn" status="${dir.status }" value="${dir.id}">
																		<c:choose>
																			<c:when test="${dir.status=='1' }">
																				发布
																			</c:when>
																			<c:when test="${dir.status=='2' }">
																				取消发布
																			</c:when>
																		</c:choose>
																	</a>
																	<c:if test="${dir.status=='2' }">
																	<!-- 
																		<a href="#" name="a_dispose" class="disposeBtn" dispose="${dir.dispose }" value="${dir.id}">
																			<c:choose>
																				<c:when test="${dir.dispose=='1' }">
																					办结
																				</c:when>
																				<c:when test="${dir.dispose=='2' }">
																					重新打开
																				</c:when>
																			</c:choose>
																		</a>&nbsp;
																	 -->
																	</c:if>
																</c:otherwise>
															</c:choose>															
														</td>
													</tr>
												</c:forEach>
											</c:otherwise>
										</c:choose>	
										<tr>
										<td colspan="8">
											<!-- 分页信息 -->
											<div class="pagination" style="text-align:right"> 
												<c:if test="${pm.result ne null}">
												<script>
													var pg = new showPages('pg');
													pg.pageCount = ${pm.maxPage};
													pg.argName = 'currentPage';
													pg.printHtml();  
												</script>
												</c:if>
											</div>
											<!-- End .pagination -->
											<div class="clear"></div>
										</td>
									</tr>
									</table>
								</td>
							</tr>																
						</table>
					</div>
				</td>
			</tr>
		</table>

	</body>
</html>